package com.aha.dataanalyzeandview.utils;




import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class ObjectUtils {


    public static <T> T isNotNull(T t ){
        if(t != null){
            return t;
        }else{
            throw new RuntimeException("对象为空：" + t );
        }
    }


    /**
     * 将Object对象里面的属性和值转化成Map对象
     *
     * @param obj
     * @return
     */
    public static Map<String, Object> objectToMap(Object obj)   {
        Map<String, Object> map = new HashMap<String,Object>();
        if (obj == null) return  map;
        Class<?> clazz = obj.getClass();
        for (Field field : clazz.getDeclaredFields()) {
            field.setAccessible(true);
            String fieldName = field.getName();
            String value = "";
            try {
                 value = String.valueOf(field.get(obj));
            }catch (IllegalAccessException e){
            }
            map.put(fieldName, value);
        }
        return map;
    }
}
